package com.applink.sell_proof.utilConvertCount;

import java.util.ArrayList;

import com.applink.sell_proof.pojo.GenericObject;

public class GenericFilter {
	
	public static ArrayList<GenericObject> getSubGenericObjectListFromAnAttribute( ArrayList<GenericObject> genericObjectList, String attributeTag1, String attributeTag2, String resultPeriod, String resultYear2) {
		
		ArrayList<GenericObject> subGenericObjectList = new ArrayList<GenericObject>();
	
		for(int i=0; i< genericObjectList.size();i++){
			
			GenericObject genericObject = genericObjectList.get(i);
			int attributeIndex = 0;
			
			boolean isSatisfiedTag1 = false;
			boolean isSatisfiedTag2 = false;
			
			if(resultPeriod.compareTo("")==0){
				isSatisfiedTag1 = true;
			}
			
			if(resultYear2.compareTo("")==0){
				isSatisfiedTag2 = true;
			}
			 
			while(attributeIndex < genericObject.getAttributeList().size()){
				
				String attributeName = String.valueOf(genericObject.getAttributeList().get(attributeIndex).getName());
				String attributeValue = String.valueOf(genericObject.getAttributeList().get(attributeIndex).getValue());
				if(attributeName.compareToIgnoreCase(attributeTag1) == 0 &&  (attributeValue.compareToIgnoreCase(resultPeriod) == 0)){
				
					 isSatisfiedTag1 = true;
				}
				
				if(attributeName.compareToIgnoreCase(attributeTag2) == 0 &&  (attributeValue.compareToIgnoreCase(resultYear2) == 0)){
					
					 isSatisfiedTag2 = true;
				}
				
				if( isSatisfiedTag1  == true && isSatisfiedTag2  == true){
					subGenericObjectList.add(genericObject);
					break;
				}
				attributeIndex++;
			}
		}
		
		return subGenericObjectList;
	}
}
